package cn.springcloud.alibaba.gateway.controller;

import cn.springcloud.alibaba.gateway.common.RouteConfigRefreshEvent;
import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import reactor.core.publisher.Mono;

@Component
@RestControllerEndpoint(id = "customGateway")
public class GatewayEndpoint implements ApplicationEventPublisherAware {

	private ApplicationEventPublisher publisher;

	@Override
	public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
		this.publisher = publisher;
	}

	@GetMapping("/refreshRouteConfig")
	public Mono<Void> refreshRoutes() {
		this.publisher.publishEvent(new RouteConfigRefreshEvent(this));
		return Mono.empty();
	}
}

